package edu.guet.server.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.guet.server.mapper.StuSemesterMapper;
import edu.guet.server.model.StuSemester;
import edu.guet.server.utils.ResultAPI;

@Service
public class StuSemesterService {
    @Autowired
    StuSemesterMapper stuSemesterMapper;

    public ResultAPI setStuSemester(StuSemester stuSemester){
        stuSemesterMapper.setStuSemester(stuSemester);
        return ResultAPI.success(stuSemester, "设置学生与学期关系成功");
    }

    public ResultAPI deleteStuSemester(int user_id, int semester_id){
        boolean result = stuSemesterMapper.deleteStuSemester(user_id, semester_id);
        return ResultAPI.success(result, "删除学生与学期关系成功");
    }

    public ResultAPI findStuSemesterBySemesterId(int semester_id){
        List<StuSemester> list = stuSemesterMapper.findStuSemesterBySemesterId(semester_id);
        return ResultAPI.success(list, "查询学生与学期关系成功");
    }

    public ResultAPI updateStuSemesterForSocre(StuSemester stuSemester){
        StuSemester old_semester = stuSemesterMapper.findStuSemesterByStuSemesterId(stuSemester.getStu_semester_id());

        boolean result = stuSemesterMapper.updateStuSemesterForSocre(stuSemester);
        if (result) {
            return ResultAPI.success(result, "更新学生与学期关系成功");
        } else {
            return ResultAPI.error("更新学生与学期关系失败");
        }
        
    }

    public ResultAPI addperStu(StuSemester stuSemester) {

        boolean result = stuSemesterMapper.addperStuSem(stuSemester);
        if (result) {
            return ResultAPI.success(result, "成功");
        } else {
            return ResultAPI.error("该学生已添加");
        }
    }
}
